from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.keys import Keys
from preceda_genfunc import *
from preceda_global import *
import unittest, time, re, csv, logging, datetime

class getfields:
    def __init__(self,objcountry,objmenu,fieldsinv):
        # =========================== Start: Fields ===========================
        # Created by: Giovanni Minoza
        # Date Created: August 14, 2013
        # Purpose: All Fields
        # Country: AU
        # =========================== Start: Fields ===========================
        #if objmenu=="Administration;Reference;Base Details;Projects":
        self.getrefproj(objcountry,objmenu,fieldsinv)
        # =========================== End: Fields ===========================

    def getrefproj(self,objcountry,objmenu,fieldsinv):
        # =========================== Start: Reference->Projects ===========================
        driver=globalflag.chb2v
        tmp=False
        if objmenu=="M001005":
            tmpstring=frefattachmentcodes(objcountry)
        elif objmenu=="M000225":
            tmpstring=frefattachmentslocation(objcountry)
        elif objmenu=="M001010":
            tmpstring=frefawardcalssificationcodes(objcountry)
        elif objmenu=="M000017":
            tmpstring=frefawardcodes(objcountry)
        elif objmenu=="M000061":
            tmpstring=frefchangereasons(objcountry)
        elif objmenu=="M001560":
            tmpstring=frefdefaultchangereason(objcountry)
        elif objmenu=="M000016":
            tmpstring=frefcountrycodes(objcountry)
        elif objmenu=="M001007":
            tmpstring=frefdependanttype(objcountry)
        elif objmenu=="M001037":
            tmpstring=frefdutyperformed(objcountry)
        elif objmenu=="M001038":
            tmpstring=frefstatus(objcountry)
        elif objmenu=="M001416":
            tmpstring=freflanguage(objcountry)
        elif objmenu=="M000034":
            tmpstring=frefnationalitycodes(objcountry)
        elif objmenu=="M000008":
            tmpstring=frefstateregioncodes(objcountry)
        elif objmenu=="M000096":
            tmpstring=frefprojects(objcountry)
        elif objmenu=="M001415":
            tmpstring=frefreligiousdenomination(objcountry)
        elif objmenu=="M000056":
            tmpstring=frefteamroles(objcountry)
        elif objmenu=="M000037":
            tmpstring=frefterminationreasons(objcountry)
        elif objmenu=="M001011":
            tmpstring=frefworkpatterncodes(objcountry)
        elif objmenu=="M001012":
            tmpstring=frefworkpatterndetails(objcountry)
        elif objmenu=="M001295":
            tmpstring=frefworkpatternroster(objcountry)
        elif objmenu=="M000577":
            tmpstring=facthiremandatoryinformation(objcountry)
        elif objmenu=="M000651":
            tmpstring=facthirepersonal(objcountry)
        elif objmenu=="M000652":
            tmpstring=facthireposition(objcountry)
        elif objmenu=="M000581":
            tmpstring=facthirepayroll(objcountry)
        elif objmenu=="M000217":
            tmpstring=facthiretax(objcountry)
        elif objmenu=="M000654":
            tmpstring=facthirecosting(objcountry)
        elif objmenu=="M000653":
            tmpstring=facthireclassification(objcountry)
        elif objmenu=="M001102":
            tmpstring=facthirecompliancedetails(objcountry)


        fieldlist=fieldsinv.split(';')
        for x in fieldlist:
            #tmp=True
            fielditem=x.split('=')

            for i in fielditem:

                storedfieldlist=tmpstring.split(';')
                for k in storedfieldlist:

                    storedfielditem=k.split('~')
                    for j in storedfielditem:

                        if i.lower()==j.lower():
                            #print driver.find_element_by_name(k[len(j)+1:len(k)]).is_displayed()
                            tmpo=driver.find_element_by_name(k[len(j)+1:len(k)]).get_attribute("class")
                            if tmpo.find("fieldreadonly")>=0:
                                tmp=False
                                break
                            else:
                                placefieldvalue(k[len(j)+1:len(k)],x[len(i)+1:len(x)],1)
                                tmp=True

            if tmp==False:
                globalflag.flagtocontinue=4
                break
        # =========================== End: Reference->Projects ===========================

def frefattachmentcodes(objcountry):
    if objcountry=="AU" or objcountry=="NZ" or objcountry=="PH":
        tmpstr="code~APKEY1;description~LDDES"
        return tmpstr

def frefattachmentslocation(objcountry):
    if objcountry=="AU" or objcountry=="NZ" or objcountry=="PH":
        tmpstr="code~AG9CODE;description~AG9DESC;location~AG9LOC"
        return tmpstr

def frefawardcalssificationcodes(objcountry):
    if objcountry=="AU" or objcountry=="NZ" or objcountry=="PH":
        tmpstr="code~AAWCCOD;description~AAWCDES"
        return tmpstr

def frefawardcodes(objcountry):
    if objcountry=="AU" or objcountry=="NZ" or objcountry=="PH":
        tmpstr="code~APKEY2;description~LDAADES;short description~LDASDES"
        return tmpstr

def frefchangereasons(objcountry):
    if objcountry=="AU" or objcountry=="NZ" or objcountry=="PH":
        tmpstr="code~ASCODE;description~LSLDESC;short description~LSSDESC"
        return tmpstr

def frefdefaultchangereason(objcountry):
    if objcountry=="AU" or objcountry=="NZ" or objcountry=="PH":
        tmpstr="module~LR026CRS;module description~LR026DESC;default reason code~AR026CODE"
        return tmpstr

def frefcountrycodes(objcountry):
    if objcountry=="AU" or objcountry=="NZ" or objcountry=="PH":
        tmpstr="code~ANCCODE;description~LNCLDES;short description~LNCSDES"
        return tmpstr

def frefdependanttype(objcountry):
    if objcountry=="AU" or objcountry=="NZ" or objcountry=="PH":
        tmpstr="description~LCHDESC"
        return tmpstr

def frefdutyperformed(objcountry):
    if objcountry=="AU" or objcountry=="NZ" or objcountry=="PH":
        tmpstr="description~LCHDESC"
        return tmpstr

def frefstatus(objcountry):
    if objcountry=="AU" or objcountry=="NZ" or objcountry=="PH":
        tmpstr="description~LCHDESC"
        return tmpstr

def freflanguage(objcountry):
    if objcountry=="AU" or objcountry=="NZ" or objcountry=="PH":
        tmpstr="language code~AR003LANG;language code description~LR003LAND"
        return tmpstr

def frefnationalitycodes(objcountry):
    if objcountry=="AU" or objcountry=="NZ" or objcountry=="PH":
        tmpstr="code~APKEY2;description~LDAADES;short description~LDASDES"
        return tmpstr

def frefstateregioncodes(objcountry):
    if objcountry=="AU" or objcountry=="NZ" or objcountry=="PH":
        tmpstr="code~ASHDESC;description~LSLDESC"
        return tmpstr
        
def frefprojects(objcountry):
    if objcountry=="AU" or objcountry=="NZ" or objcountry=="PH":
        tmpstr="project id~AJPRJID;commencement~AJCDATEVIR;completion~AJEDATEVIR;purpose1~LJPURP1;purpose2~LJPURP2;purpose3~LJPURP3;purpose4~LJPURP4;comment1~LJCOMM1;comment2~LJCOMM2;comment3~LJCOMM3"
        return tmpstr

def frefreligiousdenomination(objcountry):
    # Not present in AU
    if objcountry=="NZ" or objcountry=="PH":
        tmpstr="code~AR004RELC;description~LR004RELD"
        return tmpstr

def frefteamroles(objcountry):
    if objcountry=="AU" or objcountry=="NZ" or objcountry=="PH":
        tmpstr="code~ARROLE;description~PRFILTR;responsibilities1~LRRESP1;responsibilities2~LRRESP2;responsibilities3~LRRESP3;responsibilities4~LRRESP4;responsibilities5~LRRESP5;comments1~LRCOMM1;comments2~LRCOMM2;comments3~LRCOMM3"
        return tmpstr

def frefterminationreasons(objcountry):
    if objcountry=="AU" or objcountry=="NZ" or objcountry=="PH":
        tmpstr="code~APKEY2;description~LDAADES;short description~LDASDES"
        return tmpstr

def frefworkpatterncodes(objcountry):
    if objcountry=="AU" or objcountry=="NZ" or objcountry=="PH":
        tmpstr="code~APWKPCD;description~LPWKPDS;start date~LPWKSDTVIR;frequency~PPWKFRQ;time roster code~APWKSCD"
        return tmpstr
        
def frefworkpatterndetails(objcountry):
    if objcountry=="AU" or objcountry=="NZ" or objcountry=="PH":
        # grid
        tmpstr="workhours~PWKWHR"
        return tmpstr

def frefworkpatternroster(objcountry):
    if objcountry=="AU" or objcountry=="NZ" or objcountry=="PH":
        # grid
        tmpstr="saturday~SEBELT1;sunday~SEBELT2;monday~SEBELT3;tuesday~SEBELT4;wednesday~SEBELT5;thursday~SEBELT6;friday~SEBELT7"
        return tmpstr

def facthiremandatoryinformation(objcountry):
    if objcountry=="AU" or objcountry=="NZ" or objcountry=="PH":
        # grid
        tmpstr="copy existing id number~LXAEMPID;or enter a position id~AAPOSNO;default payroll group~APDFTGR;default costing group~ACDFTGR"
        return tmpstr

def facthirepersonal(objcountry):
    if objcountry=="AU" or objcountry=="NZ" or objcountry=="PH":
        # grid
        tmpstr="title~PATITLE;surname~LASNAME;first name~LAFNAME;middle name~LAMNAME;other name~LANNAME;preferred name~LAKNOW;report name~LAERNM;gender~AASEX;marital status~AAMART;date of birth~LABRDAT;place of birth~AMPBIRT;residential1~LAADDR;residential2~LACITY;residential3~LAADDRX;city~LAADDR3;region~PASTATE;postcode~LAPOST;country~AAACTRY;phone~LAHTEL;mobile~AAMOBVIR"
        return tmpstr

def facthireposition(objcountry):
    if objcountry=="AU" or objcountry=="NZ" or objcountry=="PH":
        # grid
        tmpstr="hire date~LAHRDATVIR;position start date~LAPSDATVIR;location~AALOCN;floor~LAFLOOR;work phone~LAWPHON;extension~LAPEXTN;probation due date~LAPRDUEVIR;apprentice~PAAPPTR"
        return tmpstr

def facthirepayroll(objcountry):
    if objcountry=="AU" or objcountry=="NZ" or objcountry=="PH":
        # grid
        tmpstr="base hours~AABASEH;work pattern code~AMWKPCD;payrun group~AAPGR;pay method~AAPAYM;auto pay~AAAUTO;fte factor~AMFCDE;freq auto increment~PAFAUTO;work pattern start week~PMWKPSQ;pay frequency~AAPAYF;auto pay hours~AAPAYHT;employee fte hours per week~SMFHPW;payslip type~AMPYSTP;delivery method~AMPSMTH;email to~AMEMLDL;email~LL_EMAIL;salary code~AAPR1CD;rate frequency~AAPR1F;base pay rate~PAPR1;award pay rate~PAPR2;other pay rate~PAPR3;pay rate 4~PMPRAT4;pay rate 5~PMPRAT5;pay rate 6~PMPRAT6;pay rate 7~PMPRAT7;pay rate 8~PMPRAT8;salary sacrifice~PASALSF;annual super gross~PAANSUP;create salary package~AH3ACT;protected net~PAPNETT;code 1~AAAVR1;rate 1~PAAVGP1;code 2~AAAVR2;rate 2~PAAVGP2;code 3~AAAVR3;rate 3~PAAVGP3;code 4~AMAVR4;rate 4~PMAVGP4;code 5~AMAVR5;rate 5~PMAVGP5;code 6~AMAVR6;rate 6~PMAVGP6;ordinary pay code~AMORPCD;ordinary pay rate~PMORPRT;gesa linked earnings code~AMGESAL;gross earnings since anniversary~PMGESA"
        return tmpstr

def facthiretax(objcountry):
    if objcountry=="AU" or objcountry=="NZ" or objcountry=="PH":
        # grid
        tmpstr="tax code~AATAXC;tax file number~AL_MTAXFN;special tax rate~PASTAX;supplementary tax~AASTC1VIR;additional tax exempt~AL_STATXE;dependant concession~PADEPC;zone~AATXZON;zone rebate~PAZNREB;loading tax exempt~PAVAC;income type~PAFTYP;payment summary type~AL_MPSTYP;australian business number~AL_ABN"
        return tmpstr

def facthirecosting(objcountry):
    if objcountry=="AU" or objcountry=="NZ" or objcountry=="PH":
        # grid
        tmpstr="company~AALVL1;state~AALVL2;division~AALVL3;unit~AALVL4;cost centre~AALVL5;department~AADEPT;account~AAACCT;clock location~LACLOCK;rack no~PARACK;ta employee~AASTRE;costing1~AMLCST1;costing2~AMLCST2;costing3~LMLCST3;costing method~AMCMTH"
        return tmpstr

def facthireclassification(objcountry):
    if objcountry=="AU" or objcountry=="NZ" or objcountry=="PH":
        # grid
        tmpstr="employment type~AAEMPT;personnel type~AADIR;security group~LASEC;award~AAAWARD;job title~AAJOBT;award classification~AMAWRD;personnel group~AAOFGRP;remuneration group~AAFRGRP;place joined~AACJOIN;organisation joined~AABJOIN;house provided~AARSTUS"
        return tmpstr

def facthirecompliancedetails(objcountry):
    if objcountry=="AU" or objcountry=="NZ" or objcountry=="PH":
        # grid
        tmpstr="event~T7EVTCD;status~T7EVTST;event date~T7EVTDTVR;expiry date~T7EVTEXVR;comment~T7EVTCO;event~T7EVTCD;status~T7EVTST;event date~T7EVTDTVR;expiry date~T7EVTEXVR;comment~T7EVTCO"
        return tmpstr
    
    
class placefieldvalue:
    # =========================== Start: Place Field Value ===========================
    # Created by: Giovanni Minoza
    # Date Created: August 14, 2013
    # Purpose: Place value of field
    # =========================== Start: Place Field Value ===========================
    def __init__(self,fieldname,fieldvalue,fieldclear):
        driver=globalflag.chb2v
        if fieldclear==1: driver.find_element_by_name(fieldname).clear()
        driver.find_element_by_name(fieldname).send_keys(fieldvalue)
        if globalflag.precedaactivity=="M000581":
            if fieldname=="AMPYSTP" or fieldname=="AMPSMTH" or fieldname=="AMEMLDL":
                driver.find_element_by_name(fieldname).send_keys("\t")
        if globalflag.precedaactivity=="M001102":
            if fieldname=="T7EVTCD" or fieldname=="T7EVTST" or fieldname=="T7EVTDTVR" or fieldname=="T7EVTEXVR" or fieldname=="T7EVTCO":
                driver.find_element_by_name(fieldname).send_keys("\t")
    # =========================== End: Place Field Value ===========================
